<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>添加合同</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
    <!--<link rel="stylesheet" type="text/css" href="CSS/bootstrap-switch.min.css" />-->
    <!--<link rel="stylesheet" type="text/css" href="CSS/addContract.css" />-->


    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="js/ajax.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script src="laydate/laydate.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>


</head>

<body>
<div class="addMain" style="margin:0px auto;width:300px;height:250px;">
    <div class="add-detail">


        合同编码：<input type="text" id="contractId" class="add-text"/>
    </div>
    <div class="add-detail">

        合同名称：<input type="text" id="contractName" class="add-text"/>
    </div>
    <div class="add-detail">

    提交人编号：<input type="text" id="userId" class="add-text"/>
    </div>
    <div class="add-detail-date">


        起始时间：<input type="text" id="start" class="laydate-icon" onclick="laydate()"/>
    </div>
    <div class="add-detail-date">


        截止时间：<input type="text" id="deadline" class="laydate-icon" onclick="laydate()"/>
    </div>
    <div>
        付款期数：<input type="text" id="times" class="add-text"/>
    </div>
    <div>

        是否提醒：<input id="checkbox1" type="checkbox" checked="checked"/>
    </div>
    <div class="add-detail-date" id="div1" style="display:block;margin-top:10px;">


        提醒时间：<input type="text" id="remind" class="laydate-icon" onclick="laydate()"/>
    </div>
    <div class="" style="display:none">
        占位：<input type="text" class="laydate-icon" onclick="laydate()"/>
    </div>
    <div class="">

        <input type="button" id="btn" class="add-receive"
               style="height:23px;width:84px;line-height:20px;font-size:12px;" value="添加"/>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    window.onload = function () {
        var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
        var oCheckbox = document.getElementById('checkbox1');
        var oDiv1 = document.getElementById('div1');
        oCheckbox.addEventListener("click", function () {
                    if (oCheckbox.checked == true) {
                        oDiv1.style.display = 'block';
                        oCheckbox.value = 1
                    }
                    else {
                        oDiv1.style.display = 'none';
                    }
                }
        );
        var btn = document.getElementById('btn');
        btn.addEventListener("click", function () {
            var contractId = document.getElementById('contractId').value;
            var contractName = document.getElementById('contractName').value;
            var start = document.getElementById('start').value;
            var deadline = document.getElementById('deadline').value;
            var checkbox1 = document.getElementById('checkbox1');
            var remind = document.getElementById('remind').value;
            var times = document.getElementById('times').value;
            var userId = document.getElementById('userId').value;
            if(contractId==""){
                layer.msg('合同编码不能为空！', function(){
                });
                return;
            }
            if(contractName==""){
                layer.msg('合同名称不能为空！', function(){
                });
                return;
            }
            if(userId==""){
                layer.msg('提交人编号不能为空！', function(){
                });
                return;
            }
            if(start==""){
                layer.msg('开始时间不能为空！', function(){
                });
                return;
            }
            if(deadline==""){
                layer.msg('截止时间不能为空！', function(){
                });
                return;
            }
            if(times==""){
                layer.msg('付款期数不能为空！不分期输入0！', function(){
                });
                return;
            }
            if(times>"24"){
                layer.msg('付款期数不能大于24！', function(){
                });
                return;
            }
            if(checkbox1.checked && remind==""){
                layer.msg('请输入提醒时间！', function(){
                });
                return;
            }
            if(remind!="" && deadline!="" && remind>deadline){
                layer.msg('提醒时间不能大于截止时间！', function(){
                });
                return;
            }
            if(!checkbox1.checked){
                remind = "2000-01-01";
            }
            mui.ajax(hosturl+"/contract/addByAdmin", {
                    data: {
                        "contractId": contractId,
                        "contractName": contractName,
                        "start": start,
                        "deadline": deadline,
                        "warnOrNor": checkbox1.checked,
                        "remind": remind,
                        "times": times,
                        "userId":userId
                    },
                    dataType: "json",
                    type: "post",
                    timeout: 10000,
                    success: function (data) {
                        if (data.status == "ok") {
                            parent.$("#handle_status").val('OK');
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        } else {
                            layer.msg(data.description, function(){
                            });
                            return;
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        console.log(type);
                    }
                });
            }
        );
    }
</script>

<script>

    !function () {
        laydate({
            elem: '#demo'
        })
    }();
</script>
</body>
</html>
<div style="display:none">
    <script type="text/javascript">
        var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
        //	document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F6f798e51a1cd93937ee8293eece39b1a' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <!--<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_5718743'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s9.cnzz.com/stat.php%3Fid%3D5718743%26show%3Dpic2' type='text/javascript'%3E%3C/script%3E"));</script>-->
</div>
